package com.ym.b2b.brand.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.brand.dao.EmBBrandDAO;
import com.ym.b2b.brand.sqlbean.EmBBrand;
import com.ym.b2b.commons.dao.BaseDao;
import com.zc.commons.base.Page;

@Repository
public class EmBBrandDAOImpl<T> extends BaseDao<T> implements EmBBrandDAO {

    public Long searchPageEmBBrandNum(EmBBrand embbrand) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embbrand);
        return (Long) find("EM_B_BRAND.searchPageEmBBrandNum", map);
    }

    public Page searchPageEmBBrand(EmBBrand embbrand, Page<EmBBrand> page) throws DataAccessException {
        page.setTotalRow(searchPageEmBBrandNum(embbrand));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embbrand);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_B_BRAND.searchPageEmBBrand", map));
        return page;
    }

    public void insertEmBBrand(EmBBrand record) throws DataAccessException {
        insert("EM_B_BRAND.insertEmBBrand", record);
    }

    public int updateEmBBrand(EmBBrand record) throws DataAccessException {
        int rows = update("EM_B_BRAND.updateEmBBrand", record);
        return rows;
    }

    public EmBBrand searchEmBBrand(Long brandId) throws DataAccessException {
        EmBBrand key = new EmBBrand();
        key.setBrandId(brandId);
        EmBBrand record = (EmBBrand) find("EM_B_BRAND.selectEmBBrand", key);
        return record;
    }

    public int deleteEmBBrand(EmBBrand emBBrand) throws DataAccessException {
        int rows = delete("EM_B_BRAND.deleteEmBBrand", emBBrand);
        return rows;
    }

    @Override
    public EmBBrand showEmBBrandDetail(EmBBrand emBBrand) throws DataAccessException {
        return (EmBBrand) find("EM_B_BRAND.showEmBBrandDetail", emBBrand);
    }

    @Override
    public void deleteMultipleEmBBrands(String brandIdList) {
        delete("EM_B_BRAND.deleteMultipleEmBBrands", brandIdList);
    }

    @Cacheable(value = "brand", key = "#emBBrand.cacheKey", condition = "#emBBrand.searchFlag eq 'tag'")
    @Override
    public List<EmBBrand> searchEmBBrand(EmBBrand emBBrand) throws DataAccessException {
    	System.out.println("---------------------------------------");
        return list("EM_B_BRAND.searchEmBBrand", emBBrand);
    }
}
